package com.bjpowernode.p2p.web;


import com.alibaba.dubbo.config.annotation.Reference;
import com.bjpowernode.common.constant.Constants;
import com.bjpowernode.p2p.model.loan.LoanInfo;
import com.bjpowernode.p2p.service.BInfoService;
import com.bjpowernode.p2p.service.LoanService;
import com.bjpowernode.p2p.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;


@Controller
public class IndexController {

    @Reference(interfaceName = "com.bjpowernode.p2p.service.LoanService",check = false,version = "1.0-SNAPSHOT",timeout = 15000)
    private LoanService loanService;
    @Reference(interfaceClass = BInfoService.class,version = "1.0-SNAPSHOT",check = false,timeout = 15000)
    private BInfoService bInfoService;
    @Reference(interfaceClass = UserService.class,check = false,version = "1.0-SNAPSHOT",timeout = 15000)
    private UserService userService;
   @RequestMapping("/index")
    public String toIndex(Model model) {
        //查询历史年华收益率
       Double historyAvgRate = loanService.queryHistoryAvgRate();
        model.addAttribute(Constants.HISTORY_AVG_RATE,historyAvgRate);
        //查询平台用户数
        Integer allUserCount =userService.queryAllUser();
        model.addAttribute(Constants.ALL_USER_COUNT,allUserCount);
        //查询平台累计成交额
       Double allMoney = bInfoService.queryAllMoney();
       model.addAttribute(Constants.ALL_MONEY,allMoney);
       //查询新手宝，product-Type=0;【新手宝】
       /**
        * 接下来页面展示的产品内容都来自于同一张表，而且查询获取的内容相同，
        * 不同之处在于获取的产品类型不同，所以我们选择把产品类型当作参数传递，一条sql解决
        * */
       List<LoanInfo> loanInfoListX = loanService.queryLoanInfo(Constants.TYPE_X);
       model.addAttribute(Constants.LOAN_INFO_LIST_X,loanInfoListX);

       //查询优选产品
       List<LoanInfo> loanInfoListY = loanService.queryLoanInfo(Constants.TYPE_Y);
       model.addAttribute("loanInfoListY",loanInfoListY);

       //查询散标产品
       List<LoanInfo> loanInfoListS = loanService.queryLoanInfo(Constants.TYPE_S);
       model.addAttribute("loanInfoListS",loanInfoListS);

       return "index";
   }

}
